package com.myz.rabbitmq.confirm.batch;

import com.myz.rabbitmq.utils.ConnectionUtils;
import com.rabbitmq.client.*;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * 消息消费者
 *
 * @author maoyz on 18-4-4.
 */
public class ConfirmBatchReceive {

    private final static String QUEUE_NAME = "confirm_batch_work_queue";

    public static void main(String[] args) throws IOException, TimeoutException {
        Connection connection = ConnectionUtils.getConnection();

        Channel channel = connection.createChannel();

        channel.queueDeclare(QUEUE_NAME, false, false, false, null);
        System.out.println("ConfirmBatchReceive Waiting Received messages...");

        channel.basicConsume(QUEUE_NAME, true, new DefaultConsumer(channel) {
            // 传送
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope,
                                       AMQP.BasicProperties properties, byte[] body)
                    throws IOException {

                String message = new String(body, "UTF-8");
                System.out.println("ConfirmBatchReceive Received '" + message + "'");
            }
        });
    }
}
